pipeline {
        agent any
        stages {

            stage('login') {
                steps {
                    withCredentials([usernamePassword(credentialsId: 'dockerhub_sartal', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
                    sh 'docker login -u $USERNAME -p $PASSWORD'
                    }
                }
            }

            stage('build'){
                    steps {
                    	sh 'sed -i "s#VIRTUAL_HOST:.*#VIRTUAL_HOST: ${GIT_BRANCH}.django.localhost#g" docker-compose.yml'
                        sh 'COLOR=${GIT_COMMIT::6}'
                        sh 'echo $COLOR'
                        sh 'docker build -t sartal/djangogirls:latest .'
                        sh 'docker push sartal/djangogirls:latest'
                    }
            }

            stage('deploy'){
                    steps {
                            sh 'docker-compose up -d'
                    }
            }
        }
}
